package cn.zswltech.gruul.biz.service.impl;

import cn.zswltech.gruul.biz.service.CockpitMobileService;
import cn.zswltech.gruul.common.dal.dao.CockpitUserMobileMapper;
import cn.zswltech.gruul.common.entity.CockpitUserMobile;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class CockpitMobileServiceImpl implements CockpitMobileService {

    @Resource
    CockpitUserMobileMapper cockpitUserMobileMapper;

    @Override
    public String mappingMobileToAccount(String mobile) {
        log.info("mobile -> account 转换， mobile={}", mobile);
        if (StringUtils.isBlank(mobile)) {
            return null;
        }
        Example example = new Example(CockpitUserMobile.class);
        example.createCriteria().andEqualTo(CockpitUserMobile.PHONE, mobile);
        List<CockpitUserMobile> users = cockpitUserMobileMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(users)) {
            return null;
        }
        return users.get(0).getAccount();
    }
}
